<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">


      <el-form-item label="加盟商" prop="agentName">
        <el-input
          v-model="queryParams.agentName"
          placeholder="请输入加盟商"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="手机号" prop="agentMobile">
        <el-input
          v-model="queryParams.agentMobile"
          placeholder="请输入手机号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>


    <el-table v-loading="loading" :data="accountList" >
      <el-table-column label="加盟商" align="center" prop="agentName" />
      <el-table-column label="手机号" align="center" prop="agentMobile" />
      <el-table-column label="总收益" align="center" prop="totalAmount" />
      <el-table-column label="可用收益" align="center" prop="avaAmount" />
      <el-table-column label="冻结收益" align="center" prop="freeAmount" />
      <el-table-column label="创建时间" align="center" prop="gmtTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.gmtTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-edit"-->
<!--            @click="handleUpdate(scope.row)"-->
<!--            v-hasPermi="['agent:account:edit']"-->
<!--          >修改</el-button>-->

          <el-button
            size="mini"
            type="text"
            icon="el-icon-s-grid"
            @click="handleOrder(scope.row)"
            v-hasPermi="['order:order:list']"
          >订单
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-s-grid"
            @click="handleBill(scope.row)"
            v-hasPermi="['agent:bill:list']"
          >账单
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 订单 -->
    <el-dialog :title="title" :visible.sync="orderOpen" v-if="orderOpen"  width="80%">
      <order-list :stationAgentId="agentId" ></order-list>
      <div slot="footer" class="dialog-footer">
        <el-button @click="orderOpen = false">关闭</el-button>
      </div>
    </el-dialog>

    <!-- 账单 -->
    <el-dialog title="加盟商账单" :visible.sync="billOpen" v-if="billOpen"  width="80%">
      <bill-list :agentId="agentId" ></bill-list>
      <div slot="footer" class="dialog-footer">
        <el-button @click="billOpen = false">关闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listAccount } from "@/api/agent/account";
import orderList from '../../order/order/index'
import billList from '../bill/index'
export default {
  name: "Account",
  components: {orderList,billList},
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // 服务商账户表格数据
      accountList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      orderOpen:false,
      billOpen:false,
      agentId: undefined,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        freeAmount: undefined,
        agentMobile: undefined,
        agentName: undefined,
        agentId: undefined,
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询服务商账户列表 */
    getList() {
      this.loading = true;
      listAccount(this.queryParams).then(response => {
        this.accountList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },


    /** 修改按钮操作 */
    handleOrder(row) {
      this.agentId = row.agentId;
      this.orderOpen = true;
      this.title = "加盟商订单";
    },

    handleBill(row) {
      this.agentId = row.agentId;
      this.billOpen = true;
    },

  }
};
</script>
